<template>
	<div class="out_box">
		<div>
			<el-button class="out_btn" type="danger" @click="setDefault">恢复默认级别</el-button>
		</div>
		<Bluetable :tHead="tHead" :tData="tableData" @switchChange="switchChange" @radioChange="radioChange"></Bluetable>
		<pagination :total="query.total" :page.sync="query.page" :limit.sync="query.limit" @pagination="getList" />
	</div>
</template>
<script>
	export default {
		data () {
			return {
				query:{
					total:0,
					page:1,
					limit:10
				},
				tHead:[
					{
						label:"序号",
						index:true
					},
					{
						prop:"NAME",
						label:"审查模块"
					},
					{
						prop:"systemsFlag",
						label:"系统审查",
						switch:true
					},
					{
						prop:"customFlag",
						label:"自定义审查",
						switch:true
					},
					{
						prop:"VAL",
						label:"警示级别",
						width:"360px",
						radio:[{label:'禁用',id:1},{label:'不推荐',id:2},{label:'慎用',id:3},{label:'关注',id:4}]
					}
				],
				tableData: [],
			}
		},
		mounted(){
			this.getList()
		},
		methods:{
			async getList () {
				let res=await this.$ptc.mzStandJson({
					mzOrZy:"zy",
					page: this.query.page,
					pageSize: this.query.limit
				})
				if(res.total>0){
					this.query.total=res.total;
					for(var i=0;i<res.rows.length;i++){
						res.rows[i].systemsFlag=res.rows[i].SYSTEMS == 1?true:false;
						res.rows[i].customFlag=res.rows[i].CUSTOM == 1?true:false
					}
					this.tableData=res.rows;
				}
			},
			async switchChange(item,row){
				var res;
				if(item == "systemsFlag"){
					res=await this.$ptc.modifySystem({
						mzOrZy:"zy",
						module:row.MODULE,
						point:row.POINT,
						systems: row[item]?1:2
					})
				}else if(item == "customFlag"){
					res=await this.$ptc.modifyCustom({
						mzOrZy:"zy",
						module:row.MODULE,
						point:row.POINT,
						custom: row[item]?1:2
					})
				}
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				if(res.code == 1){
				}else{
					this.getList()
				}
			},
			async radioChange(item,row){
				let res=await this.$ptc.modifyVal({
					mzOrZy:"zy",
					module: row.MODULE,
					point: row.POINT,
					val: row[item]
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				if(res.code == 1){
				}else{
					this.getList()
				}
			},
			async setDefault(){
				let res=await this.$ptc.mzStandDeafult({
					mzOrZy:'mz'
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				if(res.code == 1){
					this.getList()
				}
			}
		}
	}

</script>
<style lang="scss" scoped="scoped">
	.out_box{
		padding:20px;
		.out_btn{
			margin-bottom:20px;
		}
	}
	
</style>